<!-- 搜索表单 -->
<template>
    <el-card shadow="never" >
      <el-form
        label-width="77px"
        class="ele-form-search"
        @keyup.enter.native="search"
        @submit.native.prevent
      >
        <el-row :gutter="24">
          <el-col :md="5" :sm="24">
            <el-form-item label="收入类型:">
              <el-select v-model="where.incomeTypeId" clearable placeholder="请选择收入类型">
                <el-option v-for="(item, index) in incomeTypeDatas" :key="index" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="4" :sm="24">
            <el-form-item label="状态:" label-width="50px">
              <el-select v-model="where.status" clearable placeholder="请输入状态">
                <el-option v-for="(item, index) in statusEnums" :key="index" :label="item.Value" :value="item.Key" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="7" :sm="24">
            <el-form-item label="发生日期:">
              <el-date-picker v-model="where.peddingDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="daterange"
                  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 230px;">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :md="4" :sm="24">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="search"
              >
                查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    </template>
    
    <script>
      const DEFAULT_WHERE = {
        incomeTypeId:'',
        peddingDate:'',
      };
      import { QuerySysStatusEnum } from '@/api/enummanger';
      import { QueryAllChildDictViewByCode } from '@/api/systemmanager/dictmanager';
      export default {
        name: 'OtherIncomeSearch',
        data() {
          return {
            // 表单数据
            where: { ...DEFAULT_WHERE },
            incomeTypeDatas:[],
            statusEnums:[],
          };
        },
        //初始化数据
        created(){
          this.queryStatusEnums();
        },
        methods: {
    
          /* 搜索 */
          search() {
            let params = {
              pageindex: 1,
              conditions: [],
              orderBys: [{ sort: "createDate", order: 1, }],
            };

            //状态查询
            if(this.where.status ===0 || this.where.status ===1){
              params.conditions.push({
                key:"status",
                operator: 0,
                value: this.where.status,
              });
            };
    
            //收入类型
            if(this.where.incomeTypeId){
              params.conditions.push({
                key:"incomeTypeId",
                operator: 0,
                value: this.where.incomeTypeId,
              });
            }

            //发生日期
            if(this.where.peddingDate){

              params.conditions.push({
                key:"peddingDate",
                operator: 3,
                value:  this.where.peddingDate[0] + " 00:00:00",
              });

              params.conditions.push({
                key:"peddingDate",
                operator: 5,
                value:  this.where.peddingDate[1] + " 23:59:59",
              });

            }
    
            this.$emit('search', params);
          },

          /*  重置 */
          reset() {
            this.where = { ...DEFAULT_WHERE };
            this.search();
          },
         
          /* 系统状态 */
          async queryStatusEnums(){
            QueryAllChildDictViewByCode(this.Constant.C_SRLX).then((data)=>{
              this.incomeTypeDatas = [];
              this.incomeTypeDatas = data;
            });

            let sysEnums = await QuerySysStatusEnum();
            sysEnums.map(e=>{
              this.statusEnums.push({Key:e.Key,Value:e.Value});
            });
          },
        }
      };
    </script>
    